Skip to content

feat(workbench): show a /v1 example base for custom OpenAI-compatible endpoints - #7547

Merged
M4n5ter merged 3 commits into
apache:mainfrom
Xinbeok:feat/3320-base-url-v1-hint
Dec 3, 2026
Merged

M4n5ter merged 3 commits into
apache:mainfrom
Xinbeok:feat/3320-base-url-v1-hint

Conversation

@Xinbeok

@Xinbeok Xinbeok commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #7527, as promised there.

Custom OpenAI-family providers (openai-compatible, openai-responses-compatible, new-api, sub2api) now advertise https://api.example.com/v1 as a JSON Schema examples entry on baseUrl. The example is derived from the runtime adapter and model discovery kind rather than provider IDs.

The workbench connection form uses it as the Base URL placeholder. The value is never rewritten or blocked.

anthropic-compatible, cloudflare-workers-ai (which needs /ai/v1) and providers with a default base are unchanged. The iOS form is unchanged.

Closes #3320

Verification

  • cargo test -p maka-providers: passed, including the new custom_openai_endpoints_advertise_a_versioned_example_base. That test fails when api.rs is reverted to main.
  • cargo clippy -p maka-providers --all-targets -- -D warnings: passed
  • cargo fmt -p maka-providers --check: passed
  • node scripts/i18n/check.mjs: passed
  • node --test on connection-endpoint.test.mjs (new), connection-models.test.mjs and provider-catalog.test.mjs: 8 passed
  • npx biome check on the changed TS/MJS files: passed
  • node scripts/ci.mjs run contracts: one type error, products/maka/ios-shell/app/ui/HostListNotices.tsx(93,27) TS2339 (autoReconnect). This PR does not touch that file, and the same error occurs on the base commit 8c2b496.

Not run: the desktop renderer suite. No screenshot is attached.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code, used to draft the change and tests; I reviewed the patch before submission.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a breaking change or persisted-data migration?

  • Yes — describe user/data impact, in-place migration, and upgrade_compat.rs coverage under Summary above
  • No

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…oints

Custom OpenAI-family endpoints (Chat Completions, Responses, New API and
Sub2API) had no Base URL example, so a bare host root looked as valid as
a versioned base and model discovery failed against relays that serve
`/v1/models` (apache#3320).

These providers now advertise `https://api.example.com/v1` as a JSON
Schema example derived from their runtime adapter, not their name. The
connection form shows it as the placeholder and, when a bare host root
is entered, notes that most services expect a base ending in `/v1`. The
configured value stays authoritative and is never rewritten.

Closes apache#3320

Generated-by: Claude Code
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Dec 2, 2026
@Xinbeok

Xinbeok commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@M4n5ter This is the follow-up I promised in #7527: the Base URL example is derived from the runtime adapter rather than provider IDs, and the connection form only hints at /v1 for a bare host root without rewriting the value. Could you take a look when you have time? Thanks!

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English

Good direction overall — using JSON Schema examples without rewriting or blocking the configured URL is clean. One concrete bug and one small coupling to fix before merging:

  1. Bug: cloudflare-workers-ai accidentally gets https://api.example.com/v1 and the /v1 hint
    In plugins/agent/providers/src/api.rs (configuration_schema), the predicate self.facts.base_url.is_empty() + OpenaiChat | OpenaiResponses | OpenaiCompatible also matches cloudflare-workers-ai (baseUrl: "", runtimeAdapter.kind: "openai-compatible", modelDiscovery.kind: "cloudflare").
    Cloudflare Workers AI actually requires an endpoint ending in /ai/v1 (plugins/agent/providers/src/api/discovery/pages.rs rejects anything else with "Cloudflare endpoint must end with /ai/v1"), so advertising https://api.example.com/v1 and telling users to use /v1 actively misleads them.

    • Guard the condition with matches!(self.facts.model_discovery, facts::discovery::ModelDiscovery::Protocol { .. }) so only OpenAI-protocol custom endpoints receive the generic /v1 example.
    • Add ("cloudflare-workers-ai", None) to custom_openai_endpoints_advertise_a_versioned_example_base in plugins/agent/providers/tests/integration/api/mod.rs.
  2. Minor coupling between bareRootExample and the hardcoded /v1 copy
    bareRootExample in products/maka/workbench/app/connectionEndpoint.ts triggers for any schema example with a non-empty path (apiPath(example)), while ConnectionForm.tsx hardcodes "Most OpenAI-compatible services expect a base URL ending in /v1, such as {example}.". If any future provider advertises a non-/v1 example (e.g. /ai/v1 or /v2), the hint text will contradict the example. Either tighten the check (e.g. apiPath(example) === '/v1') or phrase the note generically without hardcoding OpenAI-compatible / /v1.

简体中文

整体方向和实现很干净——复用 JSON Schema 的 examples 且不静默改写或拦截用户输入,思路是对的。合入前有一个实打实的漏网 bug 和一个小耦合需要修一下:

  1. Bug:cloudflare-workers-ai 被误伤,拿到了错误的 https://api.example.com/v1 示例和 /v1 提示
    plugins/agent/providers/src/api.rs(configuration_schema)里的判断条件 self.facts.base_url.is_empty() 加 OpenaiChat | OpenaiResponses | OpenaiCompatible 还会命中 cloudflare-workers-ai(它的 baseUrl 也是 "",runtimeAdapter.kind 是 "openai-compatible",但 modelDiscovery.kind 是 "cloudflare")。
    Cloudflare Workers AI 实际要求端点以 /ai/v1 结尾(plugins/agent/providers/src/api/discovery/pages.rs 直接校验 "Cloudflare endpoint must end with /ai/v1"),给它展示 https://api.example.com/v1 和 /v1 提示会直接误导用户。

    • 在 api.rs 条件里补上 matches!(self.facts.model_discovery, facts::discovery::ModelDiscovery::Protocol { .. }) 排除 cloudflare-workers-ai;
    • 在 plugins/agent/providers/tests/integration/api/mod.rs 的 custom_openai_endpoints_advertise_a_versioned_example_base 里补上 ("cloudflare-workers-ai", None) 负例。
  2. bareRootExample 判断条件与写死的 /v1 文案存在耦合(顺手收紧)
    products/maka/workbench/app/connectionEndpoint.ts 里的 bareRootExample 只要 schema 的 example 带任意非空 path(apiPath(example))就会触发,但 ConnectionForm.tsx 里的提示文案写死了 "Most OpenAI-compatible services expect a base URL ending in /v1, such as {example}."。后续如果有其他 provider 在 schema 里声明了非 /v1 的 examples(例如 /ai/v1 或 /v2),提示语会和示例自相矛盾。建议要么把判断收紧到 apiPath(example) === '/v1',要么把提示文案改得不绑死 OpenAI-compatible 和 /v1。

Cloudflare Workers AI needs a base ending in `/ai/v1`, so only providers
with protocol model discovery advertise the generic example. The form
note now appears only when the advertised example is a `/v1` base.

Generated-by: Claude Code
@Xinbeok

Xinbeok commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@M4n5ter Thanks, both points are fixed. The example is now limited to providers with Protocol model discovery, so cloudflare-workers-ai no longer gets it, and I added it as a negative test case. bareRootExample now only fires when the example's path is exactly /v1, with tests for /ai/v1 and /v2. Could you take another look? Thanks!

@M4n5ter

M4n5ter commented Dec 3, 2026

Copy link
Copy Markdown
Member
English

One follow-up on the UI side: please drop the live bare-root note (along with bareRootExample and the new locale entries) and keep only the https://api.example.com/v1 placeholder (with cloudflare-workers-ai excluded).

  • Because bareRootExample evaluates on every keystroke, any user typing https://relay.example/v1 hits new URL("https://r") as soon as they start typing the host: SettingsInput switches from alignItems: 'center' to 'flex-start' and pushes the form down, then snaps back up once they reach /v.
  • The https://api.example.com/v1 placeholder already communicates the expected /v1 shape cleanly without adding explanatory copy under the input. (This also eliminates the copy-coupling issue in point Harden runtime, storage, gateway, credentials, and IPC inputs #2 above; if we ever want extra guidance for bare roots later, it belongs on an actual discovery failure rather than while typing.)
简体中文

补充一条 UI 方面的意见:请直接去掉输入框下面这条实时 note 提示(连同 bareRootExample 和新增的 11 个 locale 词条),只保留 https://api.example.com/v1 的 placeholder(并修复上面提到的 cloudflare-workers-ai 排除问题)。

  • bareRootExample 会随每次按键实时计算 new URL(value),导致正常手打 https://relay.example/v1 的用户一敲到 https://r 就会触发提示:SettingsInput 从垂直居中切到顶对齐、下方表单整块往下抖一行,等敲到 /v 又弹回去,对正常输入体验干扰比较明显。
  • 把 placeholder 从 https://… 改成 https://api.example.com/v1 本身已经足够直观,不需要在表单里额外堆解释性文案(同时也自然消掉了上一条里第 2 点的文案耦合问题;后续真要对裸根做补充提示,也更适合挂在真实拉取失败的错误态里,而不是输入过程中弹出)。

The live bare-root note appeared and disappeared while a URL was being
typed, shifting the form layout, as raised in review. Drop the note, its
helper and its locale entries; the versioned placeholder remains.

Generated-by: Claude Code
@Xinbeok Xinbeok changed the title feat(workbench): hint a /v1 base for bare-root OpenAI-compatible endpoints feat(workbench): show a /v1 example base for custom OpenAI-compatible endpoints Dec 3, 2026
@Xinbeok

Xinbeok commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@M4n5ter Done: the live note, bareRootExample and the locale entries are gone, so only the https://api.example.com/v1 placeholder remains, still limited to Protocol-discovery OpenAI-family providers (Cloudflare excluded). Agreed that a bare-root hint fits better in the fetch-failure state if we ever need one. Thanks!

@M4n5ter M4n5ter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean schema-driven placeholder, cloudflare-workers-ai excluded, and no live layout shift.

@M4n5ter
M4n5ter merged commit 81d0ec9 into apache:main Dec 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom OpenAI Responses relay does not append /v1 when fetching models

2 participants